package com.lucky.common.log;

import java.util.HashMap;
import java.util.Map;

public class TrcMsg {
	private static boolean initFlag = false;
	
	public static final String METHOD_BEGIN = "METHOD_BAGIN";
	public static final String METHOD_END = "METHOD_END";
	public static final String PARAM_INFO = "PARAM_INFO";
	
	public static Map<String, String> trcMap = new HashMap<String, String>();
	
	private static void init() {
		trcMap.put(METHOD_BEGIN, "[%s] start to run; %s");
		trcMap.put(METHOD_END, "[%s] end; %s");
		trcMap.put(PARAM_INFO, "%s : %s");
	}
	
	public static String getMsg(String trcCode, String ... params) {
		if(!initFlag) {
			init();
			initFlag = true;
		}
		
		String msg = (String)trcMap.get(trcCode);
		
		if(msg == null)
			return "";
		
		for(String param: params) {
			if(param != null) {
				msg = msg.replaceFirst("%s", param);
			}
		}
		
		return "{" + trcCode + "} " + msg.replaceAll("%s", "");
	}
}
